sgdk
tools.h File Reference

Misc tools methods. More...

#include "bmp.h"
#include "vdp_tile.h"
#include "vdp_bg.h"

Go to the source code of this file.

Defines

#define COMPRESSION_NONE   0
#define COMPRESSION_APLIB   1
#define COMPRESSION_RLE   3
#define COMPRESSION_MAP_RLE   4

Functions

u32 getFPS ()
 Returns number of Frame Per Second.
fix32 getFPS_f ()
 Returns number of Frame Per Second (fix32 form).
void KLog (char *text)
 KDebug log helper methods.
void KLog_U1 (char *t1, u32 v1)
void KLog_U2 (char *t1, u32 v1, char *t2, u32 v2)
void KLog_U3 (char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3)
void KLog_U4 (char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3, char *t4, u32 v4)
void KLog_U1x (u16 minSize, char *t1, u32 v1)
void KLog_U2x (u16 minSize, char *t1, u32 v1, char *t2, u32 v2)
void KLog_U3x (u16 minSize, char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3)
void KLog_U4x (u16 minSize, char *t1, u32 v1, char *t2, u32 v2, char *t3, u32 v3, char *t4, u32 v4)
void KLog_S1 (char *t1, s32 v1)
void KLog_S2 (char *t1, s32 v1, char *t2, s32 v2)
void KLog_S3 (char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3)
void KLog_S4 (char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3, char *t4, s32 v4)
void KLog_S1x (u16 minSize, char *t1, s32 v1)
void KLog_S2x (u16 minSize, char *t1, s32 v1, char *t2, s32 v2)
void KLog_S3x (u16 minSize, char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3)
void KLog_S4x (u16 minSize, char *t1, s32 v1, char *t2, s32 v2, char *t3, s32 v3, char *t4, s32 v4)
void KLog_f1 (char *t1, fix16 v1)
void KLog_f2 (char *t1, fix16 v1, char *t2, fix16 v2)
void KLog_f3 (char *t1, fix16 v1, char *t2, fix16 v2, char *t3, fix16 v3)
void KLog_f4 (char *t1, fix16 v1, char *t2, fix16 v2, char *t3, fix16 v3, char *t4, fix16 v4)
void KLog_f1x (s16 numDec, char *t1, fix16 v1)
void KLog_f2x (s16 numDec, char *t1, fix16 v1, char *t2, fix16 v2)
void KLog_f3x (s16 numDec, char *t1, fix16 v1, char *t2, fix16 v2, char *t3, fix16 v3)
void KLog_f4x (s16 numDec, char *t1, fix16 v1, char *t2, fix16 v2, char *t3, fix16 v3, char *t4, fix16 v4)
void KLog_F1 (char *t1, fix32 v1)
void KLog_F2 (char *t1, fix32 v1, char *t2, fix32 v2)
void KLog_F3 (char *t1, fix32 v1, char *t2, fix32 v2, char *t3, fix32 v3)
void KLog_F4 (char *t1, fix32 v1, char *t2, fix32 v2, char *t3, fix32 v3, char *t4, fix32 v4)
void KLog_F1x (s16 numDec, char *t1, fix32 v1)
void KLog_F2x (s16 numDec, char *t1, fix32 v1, char *t2, fix32 v2)
void KLog_F3x (s16 numDec, char *t1, fix32 v1, char *t2, fix32 v2, char *t3, fix32 v3)
void KLog_F4x (s16 numDec, char *t1, fix32 v1, char *t2, fix32 v2, char *t3, fix32 v3, char *t4, fix32 v4)
BitmapallocateBitmap (const Bitmap *bitmap)
 Allocate a new Bitmap structure which can receive unpacked bitmap data of the specified Bitmap.
If source is not packed the function only allocate space for simple shallow copy of the source.
TileSetallocateTileSet (const TileSet *tileset)
 Allocate TileSet structure which can receive unpacked tiles data of the specified TileSet.
If source is not packed the function only allocate space for simple shallow copy of the source.
MapallocateMap (const Map *map)
 Allocate Map structure which can receive unpacked map data of the specified Map.
If source is not packed the function only allocate space for simple shallow copy of the source.
ImageallocateImage (const Image *image)
 Allocate Image structure which can receive unpacked image data of the specified Image. If source is not packed the function only allocate space for simple shallow copy of the source.
BitmapunpackBitmap (const Bitmap *src, Bitmap *dest)
 Unpack the specified source Bitmap.
TileSetunpackTileSet (const TileSet *src, TileSet *dest)
 Unpack the specified TileSet structure.
MapunpackMap (const Map *src, Map *dest)
 Unpack the specified Map structure.
ImageunpackImage (const Image *src, Image *dest)
 Unpack the specified Image structure.
void unpack (u16 compression, u8 *src, u8 *dest)
 Unpack the specified source data buffer in the specified destination buffer.
if source is not packed then nothing is done.
u32 aplib_unpack (u8 *src, u8 *dest)
 Unpack (aplib packer) the specified source data buffer in the specified destination buffer.
u32 lzkn_unpack (u8 *src, u8 *dest)
 Unpack (Konami packer) the specified source data buffer in the specified destination buffer.
void rle4b_unpack (u8 *src, u8 *dest)
 Unpack (RLE 4bit packer based on Charles MacDonald code) the specified source data buffer in the specified destination buffer.
void rlemap_unpack (u8 *src, u8 *dest)
 Unpack (RLE MAP packer) the specified source data buffer in the specified destination buffer.
void rle4b_unpackVRam (u8 *src, u16 dest)
 Unpack (RLE 4bit packer based on Charles MacDonald code) the specified source data buffer directly in VRAM.

Detailed Description

Misc tools methods.

Author:
Stephane Dallongeville
Date:
08/2011

This unit provides some misc tools methods as getFPS(), unpack()...


Define Documentation

#define COMPRESSION_APLIB   1

Use aplib (appack or sixpack) compression scheme.

#define COMPRESSION_MAP_RLE   4

Use RLE compression scheme adapted for Map data.

#define COMPRESSION_NONE   0

No compression.

#define COMPRESSION_RLE   3

Use RLE compression scheme.


Function Documentation

Bitmap* allocateBitmap ( const Bitmap bitmap)

Allocate a new Bitmap structure which can receive unpacked bitmap data of the specified Bitmap.
If source is not packed the function only allocate space for simple shallow copy of the source.

Parameters:
bitmapSource Bitmap we want to allocate the unpacked Bitmap object.
Returns:
The new allocated Bitmap object which can receive the unpacked Bitmap, note that returned bitmap is allocated in a single bloc and can be released with Mem_Free(bitmap).
NULL is returned if there is not enough memory to store the unpacked bitmap.
Image* allocateImage ( const Image image)

Allocate Image structure which can receive unpacked image data of the specified Image. If source is not packed the function only allocate space for simple shallow copy of the source.

Parameters:
imageSource Image we want to allocate the unpacked Image object.
Returns:
The new allocated Image object which can receive the unpacked Image, note that returned image is allocated in a single bloc and can be released with Mem_Free(image).
NULL is returned if there is not enough memory to store the unpacked image.
Map* allocateMap ( const Map map)

Allocate Map structure which can receive unpacked map data of the specified Map.
If source is not packed the function only allocate space for simple shallow copy of the source.

Parameters:
mapSource Map we want to allocate the unpacked Map object.
Returns:
The new allocated Map object which can receive the unpacked Map, note that returned map is allocated in a single bloc and can be released with Mem_Free(map).
NULL is returned if there is not enough memory to store the unpacked map.
TileSet* allocateTileSet ( const TileSet tileset)

Allocate TileSet structure which can receive unpacked tiles data of the specified TileSet.
If source is not packed the function only allocate space for simple shallow copy of the source.

Parameters:
tilesetSource TileSet we want to allocate the unpacked TileSet object.
Returns:
The new allocated TileSet object which can receive the unpacked TileSet, note that returned tile set is allocated in a single bloc and can be released with Mem_Free(tb).
NULL is returned if there is not enough memory to store the unpacked tiles. If the source TileSet is not packed then returned TileSet allocate only memory to do NULL is returned if there is not enough memory to store the unpacked tiles.
u32 aplib_unpack ( u8 *  src,
u8 *  dest 
)

Unpack (aplib packer) the specified source data buffer in the specified destination buffer.

Parameters:
srcSource data buffer containing the packed data (aplib packer) to unpack.
destDestination buffer where to store unpacked data, be sure to allocate enough space.
Returns:
Unpacked size.
u32 getFPS ( )

Returns number of Frame Per Second.

This function actually returns the number of time it was called in the last second.
i.e: for benchmarking you should call this method only once per frame update.

fix32 getFPS_f ( )

Returns number of Frame Per Second (fix32 form).

This function actually returns the number of time it was called in the last second.
i.e: for benchmarking you should call this method only once per frame update.

u32 lzkn_unpack ( u8 *  src,
u8 *  dest 
)

Unpack (Konami packer) the specified source data buffer in the specified destination buffer.

Parameters:
srcSource data buffer containing the packed data (Konami packer) to unpack.
destDestination buffer where to store unpacked data, be sure to allocate enough space.
Returns:
Unpacked size.
void rle4b_unpack ( u8 *  src,
u8 *  dest 
)

Unpack (RLE 4bit packer based on Charles MacDonald code) the specified source data buffer in the specified destination buffer.

Parameters:
srcSource data buffer containing the packed data (RLE 4bit packer) to unpack.
destDestination buffer where to store unpacked data, be sure to allocate enough space.
void rle4b_unpackVRam ( u8 *  src,
u16  dest 
)

Unpack (RLE 4bit packer based on Charles MacDonald code) the specified source data buffer directly in VRAM.

Parameters:
srcSource data buffer containing the packed data (RLE 4bit packer) to unpack.
destVRAM destination address where to store unpacked dat.
void rlemap_unpack ( u8 *  src,
u8 *  dest 
)

Unpack (RLE MAP packer) the specified source data buffer in the specified destination buffer.

Parameters:
srcSource data buffer containing the packed data (RLE MAP packer) to unpack.
destDestination buffer where to store unpacked data, be sure to allocate enough space.
void unpack ( u16  compression,
u8 *  src,
u8 *  dest 
)

Unpack the specified source data buffer in the specified destination buffer.
if source is not packed then nothing is done.

Parameters:
compressioncompression type, accepted values:
COMPRESSION_NONE
COMPRESSION_APLIB
COMPRESSION_RLE
COMPRESSION_MAP_RLE
srcSource data buffer containing the packed data (aplib packer) to unpack.
destDestination buffer where to store unpacked data, be sure to allocate enough space.
Bitmap* unpackBitmap ( const Bitmap src,
Bitmap dest 
)

Unpack the specified source Bitmap.

Parameters:
srcbitmap to unpack.
destDestination bitmap where to store unpacked data, be sure to allocate enough space in image buffer.
If set to NULL then a dynamic allocated Bitmap is returned.
Returns:
The unpacked Bitmap.
If dest was set to NULL then the returned bitmap is allocated in a single bloc and can be released with Mem_Free(bitmap).
NULL is returned if there is not enough memory to store the unpacked bitmap.
Image* unpackImage ( const Image src,
Image dest 
)

Unpack the specified Image structure.

Parameters:
srcimage to unpack.
destDestination Image where to store unpacked data.
If set to NULL then a dynamic allocated Image is returned.
Returns:
The unpacked Image.
If dest was set to NULL then the returned image is allocated in a single bloc and can be released with Mem_Free(image).
NULL is returned if there is not enough memory to store the unpacked image.
Map* unpackMap ( const Map src,
Map dest 
)

Unpack the specified Map structure.

Parameters:
srcmap to unpack.
destDestination map where to store unpacked data, be sure to allocate enough space in tiles and tilemap buffer.
If set to NULL then a dynamic allocated Map is returned.
Returns:
The unpacked Map.
If dest was set to NULL then the returned map is allocated in a single bloc and can be released with Mem_Free(map).
NULL is returned if there is not enough memory to store the unpacked map.
TileSet* unpackTileSet ( const TileSet src,
TileSet dest 
)

Unpack the specified TileSet structure.

Parameters:
srctiles to unpack.
destDestination TileSet structure where to store unpacked data, be sure to allocate enough space in tiles and tilemap buffer.
If set to NULL then a dynamic allocated TileSet is returned.
Returns:
The unpacked TileSet.
If dest was set to NULL then the returned tiles base is allocated in a single bloc and can be released with Mem_Free(tb).
NULL is returned if there is not enough memory to store the unpacked tiles.
 All Classes Files Functions Variables Typedefs Enumerations Defines